package com.plian.system.controller.bt.loginfo;

import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.entity.sys.Loginfo;
import com.plian.system.entity.sys.Pagelist;
import com.plian.system.model.CommonCode;
import com.plian.system.model.ListResult;
import com.plian.system.model.ObjResult;
import com.plian.system.service.bt.loginfo.LogInfoService;
import com.plian.system.service.sys.log.ILoginfoService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 基础数据
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "api/loginfo")
public class LogInfoController extends BaseController {
    @Autowired
    LogInfoService logInfoService;

    ILoginfoService iLoginfoService;

    @PostMapping(value = "/list")
    public ListResult list(@RequestBody PageData pd) throws Exception {
        return logInfoService.list(pd);
    }

    @PostMapping(value = "/detail")
    public ObjResult detail(@RequestBody PageData pd){
        return logInfoService.findbyid(pd);
    }


    /**
     * 分页
     */
    @PostMapping("/listpage")
    public ListResult<Loginfo> listpage(@RequestBody PageData pd){
        Integer pageNumber = Integer.valueOf(pd.getString("pageNumber"));
        Integer pageSize = Integer.valueOf(pd.getString("pageSize"));
        int start = (pageNumber - 1) * pageSize;
        int count =  pageSize;
        Pagelist page = new Pagelist();
        page.setStart(start);
        page.setCount(count);
        List<Loginfo> cs= iLoginfoService.list(page);
        int total = iLoginfoService.total();
        page.setTotal(total);

        ListResult<Loginfo> listResult = new ListResult<>(CommonCode.SUCCESS);
        listResult.setList(cs);
        listResult.setTotal(cs.size());
        return listResult;
    }



}